
import DataStorage from "./DataStorage";

export default class DailyAwardData
{
    /*
    DialyAward规则
    如果没有记录最后一次领取时间,就从第一次开始
     */

    //最后一次领取的时间
    public lastGetAwardTime:number=-1;

    public lastAutoShowTime:number=-1;

    //领取到第几次了
    public dayCount:number=-1;

    public static dataName:string="sfgameballxiaoxiao2023Award";
    public static readonly maxDayCount:number=5;

    //重置游戏数据
    public reset()
    {
        this.dayCount=-1;
        this.lastGetAwardTime=-1;
        this.lastAutoShowTime=-1;
    }

    public load()
    {
        if(DataStorage.dataExist(DailyAwardData.dataName))
        {
            let data=DataStorage.load(DailyAwardData.dataName);
            this.dayCount=data.dayCount;
            this.lastGetAwardTime=data.lastGetAwardTime;
            this.lastAutoShowTime=data.lastAutoShowTime;
        }
        else
        {
            this.reset();
            DataStorage.save(DailyAwardData.dataName, this);
        }
    }

    public save()
    {
        DataStorage.save(DailyAwardData.dataName, this);
    }

    public updateLastAutoShowTime()
    {
        this.lastAutoShowTime=Date.now();
        this.save();
    }

    public updateLastGetAwardTime(day:number)
    {
        this.lastGetAwardTime=Date.now();
        this.dayCount=day;
        this.save();
    }

    public clear()
    {
        DataStorage.delete(DailyAwardData.dataName);
    }
}

